package com.jinxin.platform.cdsideparkmgr.service.impl;

import com.jinxin.platform.base.common.pojo.JsonResult;
import com.jinxin.platform.cdsideparkmgr.bean.CdparkmanagerProjectArea;
import com.jinxin.platform.cdsideparkmgr.mapper.CdsideparkmgrProjectAreaMapper;
import com.jinxin.platform.cdsideparkmgr.service.ICdsideparkmgrProjectAreaService;
import com.jinxin.platform.cdsideparkmgr.utils.IdWorker;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;

/**
 * All rights Reserved, Designed By www.beonelot.com
 *
 * @version: V1.0
 * @Copyright: www.beonelot.com Inc. All rights reserved.
 * @Description：
 * @Date: 2021-09-06
 * @Author: Lingnan
 **/
@Service
@Slf4j
public class CdsideparkmgrProjectAreaServiceImpl implements ICdsideparkmgrProjectAreaService {
    @Autowired
    CdsideparkmgrProjectAreaMapper cdsideparkmgrProjectAreaMapper;
    @Resource
    private IdWorker idWorker;


    @Override
    public CdparkmanagerProjectArea selectOne(HashMap param) {
        return cdsideparkmgrProjectAreaMapper.selectOne(param);
    }

    @Override
    public List<CdparkmanagerProjectArea> list(HashMap param) {
        return cdsideparkmgrProjectAreaMapper.list(param);
    }

    @Override
    public List<CdparkmanagerProjectArea> listPage(HashMap param) {
        return cdsideparkmgrProjectAreaMapper.listPage(param);
    }

    @Override
    public int listPageCount(HashMap param) {
        return cdsideparkmgrProjectAreaMapper.listPageCount(param);
    }

    @Override
    public JsonResult delete(String id) {
        if(StringUtils.isEmpty(id)){
            return JsonResult.error("Id不存在");
        }
        int result = cdsideparkmgrProjectAreaMapper.deleteByKey(id);
        if(result > 0){
            return JsonResult.ok("删除成功","");
        }
        return JsonResult.error("删除失败");
    }

    @Override
    public JsonResult saveOrUpdate(CdparkmanagerProjectArea record) {
        if (record == null){
            return JsonResult.error("参数错误，操作失败");
        }
        String id = record.getId();
        int count;
        String msg = "";
        if(StringUtils.isEmpty(id)){
            record.setId(String.valueOf(idWorker.nextId()));
            count = cdsideparkmgrProjectAreaMapper.insert(record);
            msg = "新增成功";
        }else {
            count = cdsideparkmgrProjectAreaMapper.updateByKey(record);
            msg = "更新成功";
        }
        if(count > 0){
            return JsonResult.ok(msg,"");
        }else {
            return JsonResult.error("操作失败，请重试");
        }
    }

}
